package flc.ast.utils;

import android.os.Build;

import androidx.annotation.RequiresApi;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.Period;
import java.time.temporal.ChronoUnit;

public class CalculatorUtil {
    @RequiresApi(api = Build.VERSION_CODES.O)
    public static int calculateAge(String birthdayStr) {
        // 定义日期格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        // 解析生日字符串
        LocalDate birthday = LocalDate.parse(birthdayStr, formatter);

        // 获取当前日期
        LocalDate today = LocalDate.now();

        // 计算年龄
        return Period.between(birthday, today).getYears();
    }
}
